﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PLCS.App.OrderTask.Views.Instruction
{
    /// <summary>
    /// InstructionView.xaml 的交互逻辑
    /// </summary>
    public partial class InstructionView : UserControl
    {
        public InstructionView()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button bt = sender as Button;
            if (bt.Tag.ToString() == "1")
            {
                DataGridRow row = FindVisualParent<DataGridRow>(sender as Button);
                row.DetailsVisibility = System.Windows.Visibility.Collapsed;
                bt.Tag = "0";
            }
            else
            {
                DataGridRow row = FindVisualParent<DataGridRow>(sender as Button);
                row.DetailsVisibility = System.Windows.Visibility.Visible;
                bt.Tag = "1";
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="child"></param>
        /// <returns></returns>
        public T FindVisualParent<T>(DependencyObject child) where T : DependencyObject
        {
            DependencyObject parentObject = VisualTreeHelper.GetParent(child);
            if (parentObject == null) return null;
            T parent = parentObject as T;
            if (parent != null)
                return parent;
            else
                return FindVisualParent<T>(parentObject);
        }
    }
}